package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingPlanController
 * @Author loe
 * @Date 2024-07-08
 */

@RestController
@RequestMapping("/nursing")                                            
@Api(tags = "护理计划相关接口")
public class NursingPlanController extends BaseController{

    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 查询所有护理计划
     * @return ResponseResult<List<NursingPlanVo>>
     */
    @GetMapping("/plan")
    @ApiOperation(value = "查询所有护理计划")
    public ResponseResult<List<NursingPlanVo>> searchAll() {
        List<NursingPlanVo> nursingPlanVoList = nursingPlanService.searchAll();
        return success(nursingPlanVoList);
    }

    /**
     * 新增护理计划
     * @param nursingPlanDto 护理计划实体类Dto
     * @return 成功(空)
     */
    @PostMapping("/plan")
    @ApiOperation(value = "新增护理计划")
    public ResponseResult insert(@RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.insert(nursingPlanDto);
        return success();
    }

    /**
     * 条件分页查询
     * @param name 护理计划名称
     * @param pageNum 页码（默认为1）
     * @param pageSize 每页大小（默认为10）
     * @param status 护理计划状态
     * @return ResponseResult<PageResponse<NursingPlanVo>>
     */
    @GetMapping("/plan/search")
    @ApiOperation(value = "条件分页查询")
    public ResponseResult<PageResponse<NursingPlanVo>> limitSearch(
            @ApiParam(value = "护理计划名称") String name,
            @ApiParam(value = "页码（默认为1）") Integer pageNum,
            @ApiParam(value = "每页大小（默认为10）") Integer pageSize,
            @ApiParam(value = "护理计划状态") Integer status
    ) {
        PageResponse<NursingPlanVo> pageResponse = nursingPlanService.limitSearch(name, pageNum, pageSize, status);
        return success(pageResponse);
    }

    /**
     * 根据id查询
     * @param id 护理计划ID
     * @return ResponseResult<NursingPlanVo>
     */
    @GetMapping("/plan/{id}")
    @ApiOperation(value = "根据id查询")
    public ResponseResult<NursingPlanVo> getById(
           @ApiParam(value = "护理计划ID") @PathVariable Integer id
    ) {
        NursingPlanVo nursingPlanVo = nursingPlanService.getById(id);
        return success(nursingPlanVo);
    }

    /**
     * 修改护理计划和项目关联表
     * @param nursingPlanDto
     * @return
     */
    @PutMapping("/plan/{id}")
    @ApiOperation(value = "修改护理计划和项目关联表")
    public ResponseResult update(@RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.update(nursingPlanDto);
        return success();
    }

    /**
     * 删除护理计划和项目关联表
     * @param id 护理计划ID
     * @return
     */
    @DeleteMapping("/plan/{id}")
    @ApiOperation(value = "删除护理计划和项目关联表")
    public ResponseResult delete(
            @ApiParam(value = "护理计划ID") @PathVariable Long id) {
        nursingPlanService.delete(id);
        return success();
    }

    @PutMapping("/plan/{id}/status/{status}")
    @ApiOperation(value = "启用禁用")
    public ResponseResult setStatus(
            @ApiParam(value = "护理等级ID") @PathVariable Long id,
            @ApiParam(value = "状态，0：禁用，1：启用") @PathVariable Integer status) {
        nursingPlanService.setStatus(id, status);
        return success();
    }
}
